<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-SimpleXMLRPCServer.html" />
<link rel="prev" href="module-Cookie.html" />
<link rel="parent" href="internet.html" />
<link rel="next" href="serverproxy-objects.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>18.24 xmlrpclib -- XML-RPC client access</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.23.3 Example"
  href="cookie-example.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18. internet Protocols and"
  href="internet.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.24.1 serverproxy Objects"
  href="serverproxy-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="cookie-example.html">18.23.3 Example</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">18. Internet Protocols and</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="serverproxy-objects.html">18.24.1 ServerProxy Objects</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION00202400000000000000000">
18.24 <tt class="module">xmlrpclib</tt> -- XML-RPC client access</a>
</h1>

<p>
<a name="module-xmlrpclib"></a>

<p>

<span class="versionnote">New in version 2.2.</span>

<p>
XML-RPC is a Remote Procedure Call method that uses XML passed via
HTTP as a transport.  With it, a client can call methods with
parameters on a remote server (the server is named by a URI) and get back
structured data.  This module supports writing XML-RPC client code; it
handles all the details of translating between conformable Python
objects and XML on the wire.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-4444' xml:id='l2h-4444' class="class">ServerProxy</tt></b>(</nobr></td>
  <td><var>uri</var><big>[</big><var>, transport</var><big>[</big><var>,
                               encoding</var><big>[</big><var>, verbose</var><big>[</big><var>, 
                               allow_none</var><big>[</big><var>, use_datetime</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
A <tt class="class">ServerProxy</tt> instance is an object that manages communication
with a remote XML-RPC server.  The required first argument is a URI
(Uniform Resource Indicator), and will normally be the URL of the
server.  The optional second argument is a transport factory instance;
by default it is an internal <tt class="class">SafeTransport</tt> instance for https:
URLs and an internal HTTP <tt class="class">Transport</tt> instance otherwise.  The
optional third argument is an encoding, by default UTF-8. The optional
fourth argument is a debugging flag.  If <var>allow_none</var> is true, 
the Python constant <code>None</code> will be translated into XML; the
default behaviour is for <code>None</code> to raise a <tt class="exception">TypeError</tt>.
This is a commonly-used extension to the XML-RPC specification, but isn't
supported by all clients and servers; see
<a class="url" href="http://ontosys.com/xml-rpc/extensions.php">http://ontosys.com/xml-rpc/extensions.php</a> for a description. 
The <var>use_datetime</var> flag can be used to cause date/time values to be
presented as <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.datetime</tt> objects; this is false
by default.  <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.datetime</tt>,
<tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.date</tt> and <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.time</tt>
objects may be passed to calls.  <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.date</tt> objects
are converted with a time of ``00:00:00''.
<tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.time</tt> objects are converted using today's date.

<p>
Both the HTTP and HTTPS transports support the URL syntax extension for
HTTP Basic Authentication: <code>http://user:pass@host:port/path</code>.  The 
<code>user:pass</code> portion will be base64-encoded as an HTTP `Authorization'
header, and sent to the remote server as part of the connection process
when invoking an XML-RPC method.  You only need to use this if the
remote server requires a Basic Authentication user and password.

<p>
The returned instance is a proxy object with methods that can be used
to invoke corresponding RPC calls on the remote server.  If the remote
server supports the introspection API, the proxy can also be used to query
the remote server for the methods it supports (service discovery) and
fetch other server-associated metadata.

<p>
<tt class="class">ServerProxy</tt> instance methods take Python basic types and objects as 
arguments and return Python basic types and classes.  Types that are
conformable (e.g. that can be marshalled through XML), include the
following (and except where noted, they are unmarshalled as the same
Python type):

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="left"  >Name</th>
      <th class="left"  >Meaning</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="left"   valign="baseline"><tt class="constant">boolean</tt></td>
        <td class="left"  >The <tt class="constant">True</tt> and <tt class="constant">False</tt> constants</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">integers</tt></td>
        <td class="left"  >Pass in directly</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">floating-point numbers</tt></td>
        <td class="left"  >Pass in directly</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">strings</tt></td>
        <td class="left"  >Pass in directly</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">arrays</tt></td>
        <td class="left"  >Any Python sequence type containing conformable
                  elements. Arrays are returned as lists</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">structures</tt></td>
        <td class="left"  >A Python dictionary. Keys must be strings,
                      values may be any conformable type.</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">dates</tt></td>
        <td class="left"  >in seconds since the epoch (pass in an instance of the
                 <tt class="class">DateTime</tt> class) or a
                 <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.datetime</tt>,
                 <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.date</tt> or
                 <tt class="class"><tt class="module"><a href="module-datetime.html">datetime</a></tt>.time</tt> instance</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">binary data</tt></td>
        <td class="left"  >pass in an instance of the <tt class="class">Binary</tt>
                       wrapper class</td></tr></tbody>
</table></div>

<p>
This is the full set of data types supported by XML-RPC.  Method calls
may also raise a special <tt class="exception">Fault</tt> instance, used to signal
XML-RPC server errors, or <tt class="exception">ProtocolError</tt> used to signal an
error in the HTTP/HTTPS transport layer.  Both <tt class="exception">Fault</tt> and
<tt class="exception">ProtocolError</tt> derive from a base class called
<tt class="exception">Error</tt>.  Note that even though starting with Python 2.2 you
can subclass builtin types, the xmlrpclib module currently does not
marshal instances of such subclasses.

<p>
When passing strings, characters special to XML such as "<tt class="samp">&lt;</tt>",
"<tt class="samp">&gt;</tt>", and "<tt class="samp">&amp;</tt>" will be automatically escaped.  However, it's
the caller's responsibility to ensure that the string is free of
characters that aren't allowed in XML, such as the control characters
with ASCII values between 0 and 31; failing to do this will result in
an XML-RPC request that isn't well-formed XML.  If you have to pass
arbitrary strings via XML-RPC, use the <tt class="class">Binary</tt> wrapper class
described below.

<p>
<tt class="class">Server</tt> is retained as an alias for <tt class="class">ServerProxy</tt> for backwards
compatibility.  New code should use <tt class="class">ServerProxy</tt>.

<p>

<span class="versionnote">Changed in version 2.5:
The <var>use_datetime</var> flag was added.</span>

</dl>

<p>
<div class="seealso">
  <p class="heading">See Also:</p>

  <dl compact="compact" class="seetitle">
    <dt><em class="citetitle"><a href="http://www.tldp.org/HOWTO/XML-RPC-HOWTO/index.html"
        >XML-RPC HOWTO</a></em></dt>
    <dd>A good description of XML operation and
            client software in several languages.  Contains pretty much
            everything an XML-RPC client developer needs to know.</dd>
  </dl>
  <dl compact="compact" class="seetitle">
    <dt><em class="citetitle"><a href="http://xmlrpc-c.sourceforge.net/hacks.php"
        >XML-RPC Hacks page</a></em></dt>
    <dd>Extensions for various open-source
            libraries to support introspection and multicall.</dd>
  </dl>
</div>

<p>

<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<a name="CHILD_LINKS"><strong>Subsections</strong></a>

<ul class="ChildLinks">
<li><a href="serverproxy-objects.html">18.24.1 ServerProxy Objects</a>
<li><a href="boolean-objects.html">18.24.2 Boolean Objects</a>
<li><a href="datetime-objects.html">18.24.3 DateTime Objects</a>
<li><a href="binary-objects.html">18.24.4 Binary Objects</a>
<li><a href="fault-objects.html">18.24.5 Fault Objects</a>
<li><a href="protocol-error-objects.html">18.24.6 ProtocolError Objects</a>
<li><a href="node656.html">18.24.7 MultiCall Objects</a>
<li><a href="node657.html">18.24.8 Convenience Functions</a>
<li><a href="xmlrpc-client-example.html">18.24.9 Example of Client Usage</a>
</ul>
<!--End of Table of Child-Links-->
</div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.23.3 Example"
  href="cookie-example.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18. internet Protocols and"
  href="internet.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.24.1 serverproxy Objects"
  href="serverproxy-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="cookie-example.html">18.23.3 Example</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">18. Internet Protocols and</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="serverproxy-objects.html">18.24.1 ServerProxy Objects</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
